package math;

public class BooleanVariable implements BooleanExpression{

  private String name;
  
  public BooleanVariable(String name){
    this.name = name;
  }
  
  @Override
  public int countMembers() {
    return 1;
  }

  @Override
  public Expression simplify() {
    return this;
  }
  
  @Override
  public String toString() {
    return name;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj instanceof BooleanVariable) {
      BooleanVariable var2 = (BooleanVariable) obj;
      return var2.name.equals(name);
    } else
      return false;
  }
  
  @Override
  public int hashCode() {
    return name.hashCode();
  }

  @Override
  public <R> R accept(ExpressionVisitor<R> visitor) {
    return visitor.visitBooleanVariable(this);
  }

  @Override
  public boolean matches(Expression expr) {
    if (expr instanceof BooleanVariable) {
      BooleanVariable eVar = (BooleanVariable) expr;
      return name.equals(eVar.getName());
    } else
      return false;
  }
  
  public String getName() {
    return name;
  }

  @Override
  public BooleanExpression toDNF() {
    return this;
  }
}
